package com.brooks.demo;

/**
 * @author Maoyan
 * @data 2020/10/17 16:17
 * @Version 1.0.0
 */
//线程不安全
public class ThreadTest implements Runnable {
    private int tickets = 10;
    public void run() {
        while (true){
            if (tickets <= 0) {
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"-->抢到了第"+tickets--+"张票");
        }
    }

    public static void main(String[] args) {
        ThreadTest threadTest = new ThreadTest();
        new Thread(threadTest,"小明").start();
        new Thread(threadTest,"小王").start();
        new Thread(threadTest,"小张").start();
    }
}
